// component/count.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    realCount: {
      type: Number,
      value: 1
    },
    index: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    count: 1,
    minusDisableCss: false,
    addDisableCss: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    minus: function(e) {
      var next = this.data.realCount - 1;
      if (next >= 1) {
        this.setData({
          count: next,
          realCount: next
        })
      }
      this.setData({
        minusDisableCss: next <= 1 ? true : false,
        addDisableCss: false
      });
      this.triggerEvent('change', {
        count: this.data.count,
        index: this.data.index
      }, {});
    },
    add: function(e) {
      var next = this.data.realCount + 1;
      if (next <= 99) {
        this.setData({
          count: next,
          realCount: next
        })
      }
      this.setData({
        minusDisableCss: false,
        addDisableCss: next >= 99 ? true : false
      });
      this.triggerEvent('change', {
        count: this.data.count,
        index: this.data.index
      }, {});
    }
  }

})